home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Code Resources / Jims CDEFs 1.50 / demo Source ƒ / demoWind.c < prev    next >
Encoding:
Text File  |  1995-10-27  |  17.8 KB  |  477 lines  |  [TEXT/KAHL]

  1. // -----------------------------------------------------------------------------
  2. //    File        : demoWind.c
  3. //    Date        : October 14, 1994
  4. //    Author        : Jim Stout
  5. //    Purpose        : routines used for the demoCDEF Window
  6. //
  7. // -----------------------------------------------------------------------------
  8. #include "demoWind.h"
  9.  
  10. #include "jimsCDEF.h"
  11. #include "dialogAssist.h"
  12.  
  13. extern SysEnvRec        gSysEnv;
  14. extern short             gDemoType;
  15. extern ControlHandle     gPopCtl, gPopCtl2, gPopCtl3, gBoxCtl,gRad1,gRad2;
  16. extern ControlHandle    gProgBar1, gProgBar2, gProgBar3;
  17.  
  18. MenuHandle        hDynMenu;
  19.  
  20. //=============================================================================
  21. //    create new controls - called from doNewWindow() in demoShell.c
  22. //=============================================================================
  23. void    doNewControls(WindowPtr theWindow)
  24. {
  25.     Rect            r;
  26.     short            ht;
  27.     
  28.     if(hDynMenu) {
  29.         DeleteMenu(512);
  30.         DisposeMenu(hDynMenu);
  31.     }
  32.     hDynMenu = 0;
  33.     
  34. //-----------------------------------------------------------------------------
  35. // create the "Show:" popup menu control
  36. //-----------------------------------------------------------------------------
  37.  
  38.     SetRect(&r, 10, 6, 220, 26);
  39.     
  40.     gPopCtl = NewControl(theWindow, &r, "\pShow:", true,
  41.                         popupTitleRightJust,    // right justified
  42.                         132,                    // menu id
  43.                         popupInsetFrame+45,        // ext varCode + title width
  44.                         16*popUp+ctl3D, 0L);
  45.  
  46. //-----------------------------------------------------------------------------
  47. // create the "Window color" popup menu control
  48. //-----------------------------------------------------------------------------
  49.  
  50.     SetRect(&r, 344, 4, 366, 26);
  51.     
  52.     gPopCtl2 = NewControl(theWindow, &r, "\p", true,
  53.                         popupTitleRightJust,    // right justified
  54.                         135,                    // menu id
  55.                         popupInsetFrame+
  56.                         popupIconOnly,            // ext varCode + title width
  57.                         16*popUp+ctl3D, 0L);
  58. //-----------------------------------------------------------------------------
  59. // create the "Window pattern" popup menu control
  60. //------------------------------------------------------------------tCtlValue(gPopCtl3) -1;                // get menu setting
  61.     
  62.     if(cInx)
  63.         pixPat = GetPixPat(cInx+128);
  64.     
  65.     if(pixPat) {
  66.         BackPixPat(pixPat);
  67.     }
  68.     else {
  69.         BackPat(&qd.white);
  70.     }
  71.     if(redraw) {
  72.         EraseRect(&theWindow->portRect);
  73.         DrawControls(theWindow);
  74.     }
  75.     
  76.     SetPort(savePort);
  77. }
  78.  
  79. //=============================================================================
  80. // Handle a mouse click in a control
  81. //=============================================================================
  82. void doControlClick(ControlHandle theCtl, short thePart)
  83. {
  84.  
  85. #pragma unused(thePart)
  86.  
  87.     switch(gDemoType) {
  88.         case 1:
  89.             if(theCtl == gRad1) {
  90.                 SetCtlValue(gRad1, 1);
  91.                 SetCtlValue(gRad2, 0);
  92.             }
  93.             else
  94.             if(theCtl == gRad2) {
  95.                 SetCtlValue(gRad1, 0);
  96.                 SetCtlValue(gRad2, 1);
  97.             }
  98.             else                        // checkbox
  99.                 SetCtlValue(theCtl, !GetCtlValue(theCtl));
  100.         break;
  101.     }
  102. }
  103.  
  104. //=============================================================================
  105. // Move the progress bar controls
  106. //=============================================================================
  107. void doProgress()
  108. {
  109.     short    val, max, min;
  110.     
  111. // bump the value of the progress bars
  112.  
  113.     val = GetCtlValue(gProgBar1);
  114.     max = GetCtlMax(gProgBar1);
  115.     min = GetCtlMin(gProgBar1);
  116.     
  117.     if(val < max)
  118.         SetCtlValue(gProgBar1, ++val);
  119.     else
  120.         SetCtlValue(gProgBar1, min);
  121.  
  122. // make the "barber poles" rotate
  123.  
  124.     SetCtlValue(gProgBar2, !GetCtlValue(gProgBar2));
  125.     SetCtlValue(gProgBar3, !GetCtlValue(gProgBar3));
  126. }
  127.  
  128. //=============================================================================
  129. // create a couple of 3D control samples
  130. //=============================================================================
  131. void make3DControls(WindowPtr theWindow)
  132. {
  133.     ControlHandle    hCtl;
  134.     Rect            r;
  135.     Str255            s,numStr;
  136.     short            inx,val=0;
  137.     long            num;
  138.     
  139. //-----------------------------------------------------------------------------
  140. // create a couple of check boxes
  141. //-----------------------------------------------------------------------------
  142.  
  143.     SetRect(&r, 30, 73, 130, 89);
  144.     
  145.     for(inx=1;inx<3;inx++) {
  146.         GetIndString(s, 129, 3);
  147.         num = inx;
  148.         NumToString(num, numStr);
  149.         pStrCat((char *)s, (char *)numStr);
  150.         hCtl = NewControl(theWindow, &r, s, true,
  151.                             val,                // control value
  152.                             0,                    // minimum value
  153.                             1,                    // maximum value
  154.                             16*0+checkBoxProc, 0L);
  155.  
  156.         OffsetRect(&r, 0, 26);
  157.         val=1;
  158.     }
  159.     
  160. //-----------------------------------------------------------------------------
  161. // create a couple of radio buttons
  162. //-----------------------------------------------------------------------------
  163.  
  164.     SetRect(&r, 150, 73, 250, 89);
  165.     
  166.     for(inx=1;inx<3;inx++) {
  167.         GetIndString(s, 129, 2);
  168.         num = inx;
  169.         NumToString(num, numStr);
  170.         pStrCat((char *)s, (char *)numStr);
  171.         hCtl = NewControl(theWindow, &r, s, true,
  172.                             val,                // control value
  173.                             0,                    // minimum value
  174.                             1,                    // maximum value
  175.                             16*button3D+radioButProc, 0L);
  176.  
  177.         OffsetRect(&r, 0, 26);
  178.         val=0;
  179.         if(inx==1)
  180.             gRad1 = hCtl;
  181.         else
  182.             gRad2 = hCtl;
  183.     }
  184.     
  185. //-----------------------------------------------------------------------------
  186. // create some push buttons
  187. //-----------------------------------------------------------------------------
  188.  
  189.     SetRect(&r, 260, 43, 340, 63);
  190.     
  191.     hCtl = NewControl(theWindow, &r, "\pNormal", true,
  192.                         0,                    // control value
  193.                         0,                    // minimum value
  194.                         1,                    // maximum value
  195.                         16*button3D+pushButProc, 0L);
  196.     
  197.     OffsetRect(&r, 0, 30);                    
  198.     hCtl = NewControl(theWindow, &r, "\pFixed Gray", true,
  199.                         0,                    // control value
  200.                         0,                    // minimum value
  201.                         1,                    // maximum value
  202.                         16*grayButton+pushButProc, 0L);
  203.                         
  204.     OffsetRect(&r, 0, 30);                                            
  205.     hCtl = NewControl(theWindow, &r, "\pRect", true,
  206.                         0,                    // control value
  207.                         0,                    // minimum value
  208.                         1,                    // maximum value
  209.                         16*rectButton+pushButProc, 0L);                        
  210.     
  211.     OffsetRect(&r, 0, 30);                                            
  212.     hCtl = NewControl(theWindow, &r, "\pBack Color", true,
  213.                         0,                    // control value
  214.                         0,                    // minimum value
  215.                         1,                    // maximum value
  216.                         16*button3D+pushButProc+useWBG, 0L);                                
  217. }
  218.  
  219. //=============================================================================
  220. // create some popup controls
  221. //=============================================================================
  222. void makePopupControls(WindowPtr theWindow)
  223. {
  224.     ControlHandle    theCtl;
  225.     Rect            r;
  226.     
  227. //-----------------------------------------------------------------------------
  228. // create a popup controll for the large icon menu
  229. //-----------------------------------------------------------------------------
  230.  
  231.     SetRect(&r, 20, 40, 280, 94);
  232.  
  233.     theCtl = NewControl(theWindow, &r, "\pIcons:", true,
  234.                         popupTitleRightJust,    // right justified
  235.                         133,                    // menu id
  236.                         70,                        // title width
  237.                         16*popUp+ctl3D, 0L);
  238.                         
  239. //-----------------------------------------------------------------------------
  240. // create a menu dynamically and a popup control for it.
  241. //-----------------------------------------------------------------------------
  242.  
  243.     hDynMenu = NewMenu(512, "\pDynamic");
  244.     if(hDynMenu) {
  245.         AppendMenu(hDynMenu, "\pThis menu was");
  246.         AppendMenu(hDynMenu, "\pcreated dynamically,");
  247.         AppendMenu(hDynMenu, "\pnot read from a ");
  248.         AppendMenu(hDynMenu, "\presource.");
  249.         InsertMenu(hDynMenu, -1);
  250.  
  251.         SetRect(&r, 20, 104, 280, 123);
  252.     
  253.         theCtl = NewControl(theWindow, &r, "\pDynamic:", true,
  254.                         popupTitleRightJust,    // right justified
  255.                         512,                    // menu id
  256.                         70,                        // title width
  257.                         16*popUp, 0L);
  258.     }
  259.     
  260. //-----------------------------------------------------------------------------
  261. // create a menu with colored & styled text items
  262. //-----------------------------------------------------------------------------
  263.     OffsetRect(&r, 0, 29);
  264.     theCtl = NewControl(theWindow, &r, "\pColored:", true,
  265.                     popupTitleRightJust,    // right justified
  266.                     134,                    // menu id
  267.                     70,                        // title width
  268.                     16*popUp, 0L);
  269.     
  270. //-----------------------------------------------------------------------------
  271. // create a "type in" style menu - draws symbol only
  272. //-----------------------------------------------------------------------------
  273.  
  274.     SetRect(&r, 290, 40, 315, 94);
  275.  
  276.     theCtl = NewControl(theWindow, &r, "\p", true,
  277.                         popupTitleRightJust,    // right justified
  278.                         303,                    // menu id
  279.                         popupSymbolOnly,        // title width
  280.                         16*popUp, 0L);
  281.                         
  282. //-----------------------------------------------------------------------------
  283. // create a "icon only" style menu - draws icons only
  284. //-----------------------------------------------------------------------------
  285.  
  286.     SetRect(&r, 290, 94, 330, 134);
  287.  
  288.     theCtl = NewControl(theWindow, &r, "\p", true,
  289.                         popupTitleRightJust,    // right justified
  290.                         304,                    // menu id
  291.                         popupIconOnly,            // title width
  292.                         16*popUp+popupFixedWidth, 0L);
  293.                         
  294. //-----------------------------------------------------------------------------
  295. // create a "popupCenterText" style menu - draws item text centered in ctl rect
  296. //-----------------------------------------------------------------------------
  297.  
  298.     SetRect(&r, 325, 40, 344, 94);
  299.  
  300.     theCtl = NewControl(theWindow, &r, "\p", true,
  301.                         popupTitleRightJust,    // right justified
  302.                         302,                    // menu id
  303.                         popupCenterText,        // title width
  304.                         16*popUp+useWFont, 0L);
  305. }
  306.  
  307. //=============================================================================
  308. // create a small arrow control and a large 3D arrow control - both vertical
  309. // and horizontal variations.
  310. //=============================================================================
  311. void makeArrowControls(WindowPtr theWindow)
  312. {
  313.     ControlHandle    theCtl;
  314.     Rect            r;
  315.     
  316.     SetRect(&r, 60, 66, 177, 86);
  317.     
  318.     theCtl = NewControl(theWindow, &r, "\pNumber 1:", true,
  319.                         0,                    // control value
  320.                         0,                    // minimum value
  321.                         10,                    // maximum value
  322.                         16*spinner, 0L);
  323.                         
  324.     SetRect(&r, 60, 94, 180, 121);
  325.     
  326.     theCtl = NewControl(theWindow, &r, "\pNumber 2:", true,
  327.                         0,                    // control value
  328.                         -10,                // minimum value
  329.                         10,                    // maximum value
  330.                         16*spinner+bigArrows+ctl3D, 
  331.                         0L);
  332.                         
  333.     SetRect(&r, 200, 66, 325, 86);
  334.     
  335.     theCtl = NewControl(theWindow, &r, "\pNumber 3:", true,
  336.                         0,                    // control value
  337.                         -10,                // minimum value
  338.                         10,                    // maximum value
  339.                         16*spinner+horizArrows+ctl3D, 
  340.                         0L);
  341.                         
  342.     SetRect(&r, 200, 94, 332, 121);
  343.     
  344.     theCtl = NewControl(theWindow, &r, "\pNumber 4:", true,
  345.                         0,                    // control value
  346.                         -10,                // minimum value
  347.                         10,                    // maximum value
  348.                         16*spinner+bigArrows+horizArrows, 
  349.                         0L);
  350. }
  351.  
  352. //=============================================================================
  353. // create a default date control - has both date & time
  354. //=============================================================================
  355. void makeDateControls(WindowPtr theWindow)
  356. {
  357.     ControlHandle    theCtl;
  358.     Rect            r;
  359.     
  360.     SetRect(&r, 42, 55, 300, 75);
  361.     
  362.     theCtl = NewControl(theWindow, &r, "\pDate & Time:", true,
  363.                         0,                    // ignored
  364.                         ctl3D,                // 1 for 3D
  365.                         0,                    // 1 for 24 hour time
  366.                         16*dateTime, 0L);
  367.                         
  368.     SetRect(&r, 90, 83, 300, 103);
  369.     
  370.     theCtl = NewControl(theWindow, &r, "\pDate:", true,
  371.                         0,                    // ignored
  372.                         0,                    // 1 for 3D
  373.                         0,                    // 1 for 24 hour time
  374.                         16*dateTime+dateOnly, 0L);
  375.                         
  376.     SetRect(&r, 90, 111, 300, 131);
  377.     
  378.     theCtl = NewControl(theWindow, &r, "\pTime:", true,
  379.                         0,                    // ignored
  380.                         0,                    // 1 for 3D
  381.                         only24,                // 1 for 24 hour time
  382.                         16*dateTime+timeOnly, 0L);
  383. }
  384.  
  385. //=============================================================================
  386. // create both vertical and horizontal 3D sliders
  387. //=============================================================================
  388. void makeSliderControls(WindowPtr theWindow)
  389. {
  390.     ControlHandle    theCtl;
  391.     Rect            r;
  392.     
  393.     SetRect(&r, 30, 43, 50+vWid, 43+7*vHt+21);
  394.     
  395.     theCtl = NewControl(theWindow, &r, "\p", true,
  396.                         0,                    // control value
  397.                         0,                    // minimum set by CDEF to 0
  398.                         0,                    // maximum set by CDEF to 12*ticks
  399.                         16*vSlider+ctl3D, 
  400.                         0L);                // 7 ticks - range is 2-20
  401.                         
  402.     OffsetRect(&r, 52, 0);
  403.     
  404.     theCtl = NewControl(theWindow, &r, "\p", true,
  405.                         0,                    // control value
  406.                         0,                    // minimum set by CDEF to 0
  407.                         0,                    // maximum set by CDEF to 12*ticks
  408.                         16*vSlider, 
  409.                         5L);                // 5 ticks - range is 2-20
  410.                         
  411.     OffsetRect(&r, 62, 0);
  412.     r.right = r.left+16;
  413.     
  414.     theCtl = NewControl(theWindow, &r, "\p", true,
  415.                         35,                    // control value
  416.                         0,                    // minimum
  417.                         100,                // maximum
  418.                         16*slider, 
  419.                         0L);
  420.                         
  421.     SetRect(&r, 223, 43, 223+hWid, 63+hHt);
  422.     
  423.     theCtl = NewControl(theWindow, &r, "\p", true,
  424.                         0,                    // control value
  425.                         0,                    // minimum set by CDEF to 0
  426.                         0,                    // maximum set by CDEF to 100
  427.                         16*hSlider+ctl3D, 0L);
  428.                         
  429.     OffsetRect(&r, 0, hHt+10);
  430.     
  431.     theCtl = NewControl(theWindow, &r, "\p", true,
  432.                         0,                    // control value
  433.                         0,                    // minimum set by CDEF to 0
  434.                         0,                    // maximum set by CDEF to 100
  435.                         16*hSlider, 0L);
  436.                         
  437.     OffsetRect(&r, 0, hHt+20);
  438.     r.bottom = r.top+16;
  439.     
  440.     theCtl = NewControl(theWindow, &r, "\p", true,
  441.                         35,                    // control value
  442.                         0,                    // minimum
  443.                         100,                // maximum
  444.                         16*slider+4, 0L);
  445. }
  446.  
  447. //=============================================================================
  448. // create a "normal" and "barber pole" progress bar (both horizontal)
  449. //=============================================================================
  450. void makeProgressControls(WindowPtr theWindow)
  451. {
  452.     Rect            r;
  453.     
  454.     SetRect(&r, 40, 68, 282, 82);
  455.     
  456.     gProgBar1 = NewControl(theWindow, &r, "\p", true,
  457.                         10,                    // control value
  458.                         0,                    // minimum value
  459.                         240,                // maximum value
  460.                         16*progBar, 0L);
  461.     
  462.     OffsetRect(&r, 0, 40);
  463.     
  464.     gProgBar2 = NewControl(theWindow, &r, "\p", true,
  465.                         1,                    // control value
  466.                         0,                    // minimum value
  467.                         1,                    // maximum value
  468.                         16*progBar+barberPole, 0L);
  469.                         
  470.     SetRect(&r, 315, 47, 333, 147);
  471.     
  472.     gProgBar3 = NewControl(theWindow, &r, "\p", true,
  473.                         1,                    // control value
  474.                         0,                    // minimum value
  475.                         1,                    // maximum value
  476.                         16*progBar+vertBar+roundBar+barberPole, 0L);
  477. }